package com.tmpt.controller.action;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.tmpt.dto.Result;
import com.tmpt.service.IChartService;
import com.tmpt.utils.StringUtils;

@Controller
@Scope("prototype")
public class ChartAction extends ActionSupport{
	private Logger log = Logger.getLogger(this.getClass());
	private String _keyRandom;
	private String targetTableId;
	private String chartColumn;//single chart: "dataCompanyB"
	
	private String result;	
	private List<Map<String,Object>> jsonArrayResult = new ArrayList<Map<String,Object>>();
	
	@Resource IChartService chartService;
	

	/**
	 * 
	 * @return
	 */
	public String chartMultiJson(){
		Result resultObj = new Result();
		try {
			resultObj = chartService.chartMultiJson(_keyRandom);
			String chartJson  = resultObj.getRemark();
			System.out.println("-----------:"+chartJson);

	    	this.result = chartJson;
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
	}

	public String chartSingleJson(){
		Result resultObj = new Result();
		try {
			resultObj = chartService.chartSingleJson(_keyRandom,chartColumn);
			String chartJson  = resultObj.getRemark();
			System.out.println("-----------:"+chartJson);

	    	this.result = chartJson;
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
	}
	

	public String chartPieJson(){
		Result resultObj = new Result();
		try {
			System.out.println("---------dddddddd------");
			System.out.println("-----------targetTableId:"+targetTableId);
			targetTableId = StringUtils.isNull(targetTableId)?"0":targetTableId;
			int targetTableIdInt = Integer.parseInt(targetTableId);
			resultObj = chartService.chartPieJson(_keyRandom,targetTableIdInt);
			String chartJson  = resultObj.getRemark();
			System.out.println("-----------:"+chartJson);

	    	this.result = chartJson;
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
	}
	
	public Logger getLog() {
		return log;
	}
	public void setLog(Logger log) {
		this.log = log;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public List<Map<String, Object>> getJsonArrayResult() {
		return jsonArrayResult;
	}
	public void setJsonArrayResult(List<Map<String, Object>> jsonArrayResult) {
		this.jsonArrayResult = jsonArrayResult;
	}

	public String getTargetTableId() {
		return targetTableId;
	}

	public void setTargetTableId(String targetTableId) {
		this.targetTableId = targetTableId;
	}

	public IChartService getChartService() {
		return chartService;
	}

	public void setChartService(IChartService chartService) {
		this.chartService = chartService;
	}

	public String getChartColumn() {
		return chartColumn;
	}

	public void setChartColumn(String chartColumn) {
		this.chartColumn = chartColumn;
	}

	public String get_keyRandom() {
		return _keyRandom;
	}

	public void set_keyRandom(String _keyRandom) {
		this._keyRandom = _keyRandom;
	}





	

	
}
